package com.ymatou.iapi.sellerquery.testcase;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.sellerquery.parameter.GetRefundInfoBean;
import com.ymatou.iapi.sellerquery.service.GetRefundInfoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.database.model.YmtRefundBill;
import com.ymttest.database.sqlwapper.YmtRefundWapper;
import com.ymttest.utils.DataUtil.Random;
import com.ymttest.utils.constant.ECode;
/**
*获取退款信息接口
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetRefundInfo{
	private static GetRefundInfoBean getrefundinfoBean;
	private static GetRefundInfoCall getrefundinfoCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取退款信息接口");
	}

	@Before
	public void caseUp() {
		getrefundinfoBean=new GetRefundInfoBean();
		getrefundinfoCall=new GetRefundInfoCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getrefundinfoCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetRefundInfo_001() {
		Logger.start(true,"获取退款信息成功");
		try {
            YmtRefundWapper ymtRefund = new YmtRefundWapper();
            List<YmtRefundBill> ymtRefundBillList=ymtRefund.selectRefundBill(null);
            //从数据库里随机取一个退款单号
            YmtRefundBill randomYmtRefundBill=ymtRefundBillList.get(new java.util.Random().nextInt(9));
           String refundNo=randomYmtRefundBill.getRefundBillNo();
            String param="RefundNo="+refundNo;
			//getrefundinfoBean.setRefundNo("TK105913829");
			getrefundinfoCall.setData(param);
			getrefundinfoCall.callService();		
	
			JSONObject data=getrefundinfoCall.getData();		
			Logger.verifyEquals(ECode.SUCCESS, getrefundinfoCall.getCode(), "验证code");
			Logger.verifyEquals(0, getrefundinfoCall.getBCode(), "验证bcode");
			Logger.verifyEquals(randomYmtRefundBill.getOrderId(), data.getInt("orderId"), "验证orderId");
			Logger.verifyEquals(randomYmtRefundBill.getRefundBillNo(), data.getString("refundNo"), "验证refundNo");
			Logger.verifyEquals(randomYmtRefundBill.getRefundAmount().setScale(1).toString(), data.getString("total"), "验证total");
			Logger.verifyEquals(randomYmtRefundBill.getRefundedAmountOfCash().setScale(1).toString(), data.getString("refundedCash"), "验证refundedCash");
			Logger.verifyEquals(randomYmtRefundBill.getRefundedAmountOfGift().setScale(1).toString(), data.getString("refundedGift"), "验证refundedGift");
			Logger.verifyEquals(true, data.getBoolean("success"), "验证success");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_GetRefundInfo_002() {
		Logger.start(true,"退款单号不存在");
		try {
           String refundNo="sssss";
            String param="RefundNo="+refundNo;
			getrefundinfoCall.setData(param);
			getrefundinfoCall.callService();		
	
			JSONObject data=getrefundinfoCall.getData();		
			Logger.verifyEquals(ECode.SUCCESS, getrefundinfoCall.getCode(), "验证code");
			Logger.verifyEquals(0, getrefundinfoCall.getBCode(), "验证bcode");
			Logger.verifyEquals(0, data.getInt("orderId"), "验证orderId");
			Logger.verifyEquals("null", data.getString("refundNo"), "验证refundNo");
			Logger.verifyEquals("null", data.getString("total"), "验证total");
			Logger.verifyEquals("null", data.getString("refundedCash"), "验证refundedCash");
			Logger.verifyEquals("null", data.getString("refundedGift"), "验证refundedGift");
			Logger.verifyEquals(true, data.getBoolean("success"), "验证success");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_GetRefundInfo_003() {
		Logger.start(true,"退款单号为null");
		try {
           String refundNo=null;
            String param="RefundNo="+refundNo;
			getrefundinfoCall.setData(param);
			getrefundinfoCall.callService();		
	
			JSONObject data=getrefundinfoCall.getData();		
			Logger.verifyEquals(ECode.SUCCESS, getrefundinfoCall.getCode(), "验证code");
			Logger.verifyEquals(0, getrefundinfoCall.getBCode(), "验证bcode");
		/*	Logger.verifyEquals(.getOrderId(), data.getInt("orderId"), "验证orderId");
			Logger.verifyEquals(randomYmtRefundBill.getRefundBillNo(), data.getString("refundNo"), "验证refundNo");
			Logger.verifyEquals(randomYmtRefundBill.getRefundAmount().setScale(1).toString(), data.getString("total"), "验证total");
			Logger.verifyEquals(randomYmtRefundBill.getRefundedAmountOfCash().setScale(1).toString(), data.getString("refundedCash"), "验证refundedCash");
			Logger.verifyEquals(randomYmtRefundBill.getRefundedAmountOfGift().setScale(1).toString(), data.getString("refundedGift"), "验证refundedGift");*/
			Logger.verifyEquals(false, data.getBoolean("success"), "验证success");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}